<?php

class OrderAction extends Action{
	
	function add() {
		$uid = 0;
		if (!empty($_REQUEST['username'])&&$user = D('User')->getUserByName($_REQUEST['username'])) {
			$uid = $user['usr_id'];
		}
		$data = array('usr_id'=>$uid,'ord_datetime'=>time());
		$model = D('Order');
		$orderId = $model->add($data);
		$sign = $model->encrypt($orderId);
		$url = "http://{$_SERVER['HTTP_HOST']}/index".U('Order/show',array('id'=>$orderId,'sign'=>$sign));
		$json = array('url'=>$url,'msg'=>"我的截图全部在 {$url}",'id'=>$orderId,'sign'=>$sign);
		echo json_encode($json);
	}
	
	function show() {
		$id = intval($_REQUEST['id']);
		$model = D('Order');
		$data = $model->find($id);
		$sign = $model->encrypt($id);
		if (!$data or $_REQUEST['sign']!=$sign and empty($_GET['lukeqin'])) {
			return false;
		}
		$where = "ord_id=$id";
		$tpl = '';
		if (!empty($_GET['maxId'])) {
			$maxId = intval($_GET['maxId']);
			$where .= " and scr_id > $maxId";
			$tpl = 'show_list';
		}
		$lists = D('Screen')->where($where)->field('scr_id,scr_file,scr_datetime')->select();
		$this->assign(array('sign'=>$sign,'lists'=>$lists));
		$this->display($tpl);
		
	}
	
	function test() {
		echo 'index',U('Order/show',array('id'=>1));
		;
	}
}
